package cn.fornever.tools.db;

import cn.fornever.tools.db.assist.entity.ColumnInfo;
import cn.fornever.tools.db.assist.entity.JDBCConnectionConfig;
import cn.fornever.tools.db.assist.entity.TableInfo;
import org.junit.Assert;
import org.junit.Test;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.List;

/**
 * 数据库工具类--测试
 *
 * @author ZhangAY
 */
public class DBUtilTestSqlServer extends DBUtilTestBase {

    private static String driverClass_SQLSERVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private static String connectionURL_SQLSERVER = "jdbc:sqlserver://221.235.86.48:1433;DatabaseName=ESDB";
    private static String userName_SQLSERVER = "sa";
    private static String password_SQLSERVER = "Beijinghuitu1!";
    private String catalog = "ESDB";
    private String schema = "dbo";
    private String tableNamePattern = "%";

    static JDBCConnectionConfig config_SQLSERVER = new JDBCConnectionConfig(driverClass_SQLSERVER, connectionURL_SQLSERVER, userName_SQLSERVER, password_SQLSERVER);


    @Test
    public void getDatabaseMetaData() {
        Connection connection = DBUtil.getConnection(config_SQLSERVER);
        DatabaseMetaData metaData = DBUtil.getDatabaseMetaData(connection);
        Assert.assertTrue(metaData != null);
        DBUtil.closeConnection(connection);
    }

    //http://www.cnblogs.com/lbangel/p/3487796.html
    @Test
    public void getTableInfo() {
        Connection connection = DBUtil.getConnection(config_SQLSERVER);
        List<TableInfo> list = getTableInfo(connection,catalog,schema,tableNamePattern,null);
        DBUtil.closeConnection(connection);
        Assert.assertTrue(list != null);
    }

    @Test
    public void getColumnInfo() {
        Connection connection = DBUtil.getConnection(config_SQLSERVER);
        List<ColumnInfo> list = getColumnInfo(connection,catalog,schema,tableNamePattern,null);
        DBUtil.closeConnection(connection);
        Assert.assertTrue(list != null);
    }

}